package com.quikin.persistence.stdjpa.controller.aa;

import java.util.Collection;
import java.util.HashMap;

import org.apache.log4j.Logger;

import com.quikin.persistence.jpa.entity.aa.AuthenticationInfo;
import com.quikin.persistence.jpa.util.QuikinPLErrorCode;
import com.quikin.persistence.jpa.util.QuikinPLException;
import com.quikin.persistence.stdjpa.controller.AbstractController;

public class AuthenticationInfoController extends AbstractController<AuthenticationInfo, String>{
    
    private static final Logger logger = Logger.getLogger(AuthenticationInfoController.class);
    
    private static AuthenticationInfoController instance;
    
    private AuthenticationInfoController() {
        
    }
    
    public static AuthenticationInfoController getInstance() {
        if (instance == null) {
            instance = new AuthenticationInfoController();
        }
        return instance;
    }

    public AuthenticationInfo getByLoginId(String loginId) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("loginId", loginId);
        Collection<AuthenticationInfo> infos = find("AuthenticationInfo.getByLoginId", params, AuthenticationInfo.class);
        if (infos == null) {
            return null;
        }
        if (infos.isEmpty()) {
            return null;
        }
        if (infos.size() > 0) {
            throw new QuikinPLException(QuikinPLErrorCode.DATA_INCORRECT);
        }
        return infos.iterator().next();
    }

    @Override
    protected Class<AuthenticationInfo> getEntityClass() {
        return AuthenticationInfo.class;
    }
}
